home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / lib / uw_perror.c < prev    next >
C/C++ Source or Header  |  1991-01-25  |  1KB  |  53 lines

  1. /*
  2.  *    uw library - uw_perror
  3.  *
  4.  * Copyright 1986 by John D. Bruner.  All rights reserved.  Permission to
  5.  * copy this program is given provided that the copy is not sold and that
  6.  * this copyright notice is included.
  7.  */
  8. #include "uwlib.h"
  9.  
  10. char *uwerrlist[] = {
  11.     "no error",
  12.     "system call error",
  13.     "nonexistent window type",
  14.     "window ID duplicated (in use)",
  15.     "operation not implemented",
  16.     "non-existent server",
  17.     "unable to allocate required memory",
  18.     "invalid argument to function",
  19.     "no control file descriptor for window",
  20. };
  21. unsigned uwnerr = sizeof uwerrlist / sizeof uwerrlist[0];
  22.  
  23. int uwerrno;
  24.  
  25. /*ARGSUSED*/
  26. void
  27. uw_perror(mesg, uwerr, errno)
  28. char *mesg;
  29. uwerr_t uwerr;
  30. int errno;
  31. {
  32.     register char *errmsg;
  33.  
  34.     /*
  35.      * Print a UW error message.  We call write() directly to avoid
  36.      * making the UW library dependent upon stdio.
  37.      */
  38.     if (uwerr == UWE_ERRNO) {
  39.         perror(mesg);
  40.     } else {
  41.         if (mesg != (char *)0) {
  42.             (void)write(2, mesg, strlen(mesg));
  43.             (void)write(2, ": ", 2);
  44.         }
  45.         if (uwerr >= uwnerr)
  46.             errmsg = "unknown UW error";
  47.         else
  48.             errmsg = uwerrlist[uwerr];
  49.         (void)write(2, errmsg, strlen(errmsg));
  50.         (void)write(2, "\n", 1);
  51.     }
  52. }
  53.